using System;
using System.Collections.Generic;
using System.Text;
using IdeaDomain.DomainLayer.Entities;
using IdeaDomain.DomainLayer.RepositoryInterfaces;
using IdeaDomain.ServiceLayer;
using Container = GeneralUtilities.Utilities.Unity.Container;

namespace IdeaDomain.DomainLayer
{
    public class IdeaDataService : IIdeaDataService
    {

        public IIdeaDataRepository IdeaDataRepository { get; set; }

        public IdeaDataService(IIdeaDataRepository ideaDataRepository)
        {
            IdeaDataRepository = Container.Resolve<IIdeaDataRepository>();
        }

        /// <summary>
        /// Gets the row by id.
        /// </summary>
        /// <param name="rowId">The row id.</param>
        /// <param name="userId">The user id.</param>
        /// <returns></returns>
        public Row GetRowById(int rowId, int userId)
        {
            var row = IdeaDataRepository.GetRowById(rowId, userId);
            return row;
        }

        /// <summary>
        /// Creates the row.
        /// </summary>
        /// <param name="row">The row.</param>
        /// <returns></returns>
        public bool CreateRow(Row row)
        {
            var result = false;
            result = IdeaDataRepository.CreateRow(row);
            return result;
        }

        /// <summary>
        /// Updates the row.
        /// </summary>
        /// <param name="row">The row.</param>
        /// <returns></returns>
        public bool UpdateRow(Row row)
        {
            var result = false;
            result = IdeaDataRepository.UpdateRow(row);
            return result;
        }

        /// <summary>
        /// Deletes the row.
        /// </summary>
        /// <param name="rowId">The row id.</param>
        /// <param name="userId">The user id.</param>
        /// <returns></returns>
        public bool DeleteRow(int rowId, int userId)
        {
            var result = false;
            result = IdeaDataRepository.DeleteRow(rowId, userId);
            return result;
        }

        /// <summary>
        /// Gets the idea data.
        /// </summary>
        /// <param name="ideaId"></param>
        /// <param name="sidx"></param>
        /// <param name="sord"></param>
        /// <param name="page"></param>
        /// <param name="rows"></param>
        /// <param name="filters"></param>
        /// <returns></returns>
        public IdeaDetail GetIdeaData(int ideaId, string sidx, string sord, int page, int rows, string filters)
        {
            //Idea idea = GetIdeaById(ideaId);
            //ToChange
            Idea idea = null;
            if (idea == null)
            {
                throw new Exception("The Idea has't been created!");
            }
            return IdeaDataRepository.GetIdeaData(idea, sidx, sord, page, rows, filters);
        }

        /// <summary>
        /// Gets the idea data.
        /// </summary>
        /// <param name="idea">The idea.</param>
        /// <param name="sidx">The sidx.</param>
        /// <param name="sord">The sord.</param>
        /// <param name="page">The page.</param>
        /// <param name="rows">The rows.</param>
        /// <param name="filters">The filters.</param>
        /// <returns></returns>
        public IdeaDetail GetIdeaData(Idea idea, string sidx, string sord, int page, int rows, string filters)
        {
            return IdeaDataRepository.GetIdeaData(idea, sidx, sord, page, rows, filters);
        }

        /// <summary>
        /// Counts the idea rows.
        /// </summary>
        /// <param name="idea">The idea.</param>
        /// <param name="filters"></param>
        /// <returns></returns>
        public int CountIdeaRows(Idea idea, string filters)
        {
            return IdeaDataRepository.CountIdeaRows(idea, filters);
        }

    }
}
